package com.crscd.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2025/10/5-18:25
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RestController
public class ChatMemory4RedisController {
  @Qualifier("qwenChatClient")
  @Autowired
  private ChatClient chatClient;

  @GetMapping("/chatmemory/chat")
  public String chat(String question, String userId) {
    return chatClient
        .prompt()
        .advisors(
            advisor -> {
              advisor.param(CONVERSATION_ID, userId);
            })
        .user(question)
        .call()
        .content();
  }
}
